package reflect;

import reflect.annotation.AutoRunClass;

import java.io.File;

public class Test3 {
    public static void main(String[] args) throws Exception {
        File dir = new File(Test3.class.getResource(".").toURI());
        File packageName = new File(Test3.class.getPackage().getName());
        File[] files = dir.listFiles(f -> f.getName().endsWith(".class"));
        for (File file : files) {
            String className = file.getName().split("\\.")[0];
            Class<?> clazz = Class.forName(packageName + "." + className);
            if (clazz.isAnnotationPresent(AutoRunClass.class)) {
                Object obj = clazz.newInstance();
                System.out.println(obj + "被实例化...");
            }
        }
    }
}
